﻿using KTD.Web.BLL;
using KTD.Web.Models.VD;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XXS.Common;
using XXS.Common.ControllerExt;

namespace KTD.Web.Controllers
{
    public class CustomerRecordController : Controller
    {
       
        // GET: CustomerRecord
        public ActionResult Index(CustomerRecordQD im)
        {
            im.PageSize = 10;
            var res = MF.CustomerRecordManager.GetListBy(im);
            return View(res);
        }

        [HttpPost]
        public ActionResult Create(CustomerRecordCUD im)
        {
            MF.CustomerRecordManager.Create(im);
            return this.JsonNet(new { success = true }, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Update(CustomerRecordUD im)
        {
            MF.CustomerRecordManager.Update(im);
            return this.JsonNet(new { success = true }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Delete(int Id)
        {
            try
            {
                MF.CustomerRecordManager.Delete(Id);
                return this.JsonNet(new { success = true }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }


        public ActionResult Find(int Id)
        {
            try
            {
                var res = MF.CustomerRecordManager.Find(Id);
                return this.JsonNet(new { success = true, data = res }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }

        public ActionResult GetList(CustomerRecordQD im)
        {
            try
            {
                var res = MF.CustomerRecordManager.GetListBy(im);
                return this.JsonNet(res.ToExtGrid(), JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }

     
    }


}